package com.studytest.yiqilaidati.controller;


import com.studytest.yiqilaidati.modle.Respbody;
import com.studytest.yiqilaidati.modle.User;
import com.studytest.yiqilaidati.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserLogin {

    @Autowired
    private UserService userService;

    @CrossOrigin(origins = "http://localhost:8080")
    @ResponseBody
    @RequestMapping("/login")
    public Respbody  checkUser(@RequestParam(value = "userName")String name,
                             @RequestParam(value = "password")String password){
        Respbody result = userService.userLogin(name, password);



        return  result;
    }
    @ResponseBody
    @RequestMapping("/findAll")
    public String findAllUser(){
        List<User> allUsers = userService.findAllUsers();
        return allUsers.toString();
    }
    @ResponseBody
    @RequestMapping("/save")
    public String saveUser(User user){
        String result = userService.saveUsers(user);
        return result;
    }
    @ResponseBody
    @RequestMapping("/update")
    public String updateUser(User user){
        String result = userService.updateUsers(user);
        return result;
    }

}
